<%@page import="com.keta.foundation.entity.Module"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	trimDirectiveWhitespaces="true" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include.inc.jsp"%>

<%! 
	public String getTreeJson(String basePath,List<Module> listModule) {
		
		StringBuilder builder = new StringBuilder();
		builder.append("[");
		for (Module module : listModule) {
	
			long pid = module.getParent() == null ? 0 : module.getParent()
					.getId();
			builder.append("{id:" + module.getId() + ", pId:" + pid
					+ ", name:\"" + module.getName() + "\", url:\"" + basePath
					+ "/" + module.getId() + "\", target:\"ajax\"},");
		}
		builder.append("]");
	
		return builder.toString();
	}
%>
<%
	List<Module> moduleList = (List<Module>)request.getAttribute("moduleList");
	String tree = getTreeJson(request.getContextPath()+"/module/list",moduleList);
%>

<script type="text/javascript">
var setting = {
	view: {
		//showIcon: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		onClick: function(event, treeId, treeNode) {
			var $rel = $("#ajaxBox2moduleList");
			$rel.loadUrl(treeNode.url, {}, function(){
				$rel.find("[layoutH]").layoutH();
			});

			event.preventDefault();
		}
	}	
};
var zNodes =<%=tree %>;
$(document).ready(function(){
	var t = $("#moduleTree");
	t = $.fn.zTree.init(t, setting, zNodes);
	t.expandAll(true); 
});
</script>
<ul id="moduleTree" class="ztree"></ul>
